package com.zyd.blog.personal.controller;

import com.zyd.blog.business.annotation.BussinessLog;
import com.zyd.blog.business.enums.PlatformEnum;
import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.homeart.service.BackstageRotationChartService;
import com.zyd.blog.homeart.service.BackstageSoftProductService;
import com.zyd.blog.homeart.service.ICommentService;
import com.zyd.blog.homeart.util.ResponseObject;
import com.zyd.blog.homeart.util.UuidUtil;
import com.zyd.blog.persistence.beans.DesignArticle;
import com.zyd.blog.persistence.beans.SoftProduct;
import com.zyd.blog.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liusongqi
 * @since 2020-03-23
 */
@Controller
@RequestMapping("/backstageRotationChart")
public class BackstageRotationChartController {
    private final Logger logger = LoggerFactory.getLogger(BackstageRotationChartController.class);
    @Autowired
    private BackstageRotationChartService backstageRotationChartService;
    @Autowired
    private ICommentService iCommentService;
    @Autowired
    private UuidUtil uuidUtil;
    /**     家装设计   后台人员内部发送的文章
     *    渲染
     */
    @RequestMapping(value = "/softAll", method = RequestMethod.POST)
    @ResponseBody
    public PageResult soft(int page, int count) {
        logger.info("/backstageRotationChart/softAll 软装产品 全部,page={},count={}",page,count);
        return backstageRotationChartService.softBackstage(page,count);
    }
    @BussinessLog("软装产品")
    @GetMapping(value = "/get")
    public ModelAndView backstageSoft(Model model, String id,String userId) {
        logger.info("/backstageRotationChart/get 跳转详情,id={}",id);
        model.addAttribute("item",id);
        model.addAttribute("userId",userId);
        return ResultUtil.view("rotationChart/designDetail");
    }
    @RequestMapping(value = "/getInfo", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVO get(String id) {
        logger.info("/backstageRotationChart/getInfo 弹窗,id={}",id);
        return ResultUtil.success(null, backstageRotationChartService.get(id));
    }
    @BussinessLog("软装产品")
    @GetMapping(value = "/pass")
    public ModelAndView pass(Model model, String id) {
        logger.info("/backstageRotationChart/get 审核,id={}",id);
        model.addAttribute("item",id);
        return ResultUtil.view("rotationChart/beforeAudit");
    }
    @BussinessLog("新增软装产品")
    @GetMapping(value = "/addSoft")
    public ModelAndView adSoft(Model model) {
        logger.info("/backstageRotationChart/adSoft 新增界面");
        return ResultUtil.view("soft/releaseSoftIndex");
    }
    /**
     *     根据文章 id  获取具体内容
     */
    @RequestMapping(value = "/specific", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject specific(String designId)  {
        logger.info("/backstageRotationChart/specific 获取具体内容, designId={}", designId);
        ResponseObject ob = new ResponseObject();
        Map<String,Object> specific;
        try {
            specific = backstageRotationChartService.specific(designId);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        ob.setCode(0);
        ob.setData(specific);
        ob.setMsg("success");
        return ob;
    }
    /**
     *     ui图 115  全部评论 以及评论回复的 3条
     */
    @RequestMapping(value = "/allComment", method = RequestMethod.POST)
    @BussinessLog(value = "/backstageRotationChart/allComment 全部评论 ", platform = PlatformEnum.WEB, save = false)
    @ResponseBody
    public ResponseObject allComment(String answerId) {
        ResponseObject ob = new ResponseObject();
        Map<String, List> comment;
        try {
            comment = iCommentService.HTComment(answerId,"1");
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        ob.setCode(0);
        ob.setData(comment);
        ob.setMsg("success");
        return ob;
    }
    //添加文章 软装设计
    @RequestMapping(value = "/insertSoft", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject insertFineArt(DesignArticle designArticle, String list) {
        logger.info("/backstageRotationChart/insertSoft 发布软装设计，softProduct={},list={}",designArticle,list);
        ResponseObject ob = new ResponseObject();
        Integer integer;
        integer = backstageRotationChartService.insertSoft(designArticle,list);
        uuidUtil.importSongData();
        ob.setCode(0);
        ob.setData(integer);
        ob.setMsg("success");
        return ob;
    }

    // 软装设计
    @RequestMapping(value = "/updateIn", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVO updateIn(DesignArticle designArticle) {
        logger.info("/backstageRotationChart/updateIn 修改启用，designArticle={}",designArticle);
        return  ResultUtil.success(null, backstageRotationChartService.updateIn(designArticle));
    }
    //修改 软装设计
    @RequestMapping(value = "/editSoft", method = RequestMethod.POST)
    public ResponseObject editSoft(DesignArticle designArticle,String list,String id) {
        logger.info("/backstageRotationChart/editSoft 修改软装设计，designArticle={},list={}",designArticle,list);
        ResponseObject ob = new ResponseObject();
        Integer integer;
        try {
            integer = backstageRotationChartService.editSoft(designArticle,list,id);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        uuidUtil.importSongData();
        ob.setCode(0);
        ob.setData(integer);
        ob.setMsg("success");
        return ob;
    }

    //删除 软装设计
    @RequestMapping(value = "/deleteSoft", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVO deleteSoft(String[] ids) throws Exception {
        logger.info("/backstageRotationChart/deleteSoft 删除软装设计，ids={}",ids);
        for (String id : ids) {
            backstageRotationChartService.deleteSoft(id);
        }
        uuidUtil.importSongData();
        return ResultUtil.success("成功删除 [" + ids.length + "] 个文章类型");
    }



    //搜索
    @RequestMapping(value = "/searchSoft", method = RequestMethod.POST)
    public ResponseObject searchDesign(String value, int page, int count) {
        logger.info("/backstageRotationChartbackstageRotationChart/searchSoft 搜索,value={},page={},count={}",value,page,count);
        ResponseObject ob = new ResponseObject();
        Map<String,Object> integer;
        try {
            integer = backstageRotationChartService.searchDesign(value,page,count);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        ob.setCode(0);
        ob.setData(integer);
        ob.setMsg("success");
        return ob;
    }
    /**
     *     审核成功
     */
    @RequestMapping(value = "/success", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject success(String designId)  {
        logger.info("/backstageRotationChart/success 审核成功, designId={}", designId);
        ResponseObject ob = new ResponseObject();
        Integer specific;
        try {
            specific = backstageRotationChartService.success(designId);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        uuidUtil.importSongData();
        ob.setCode(0);
        ob.setData(specific);
        ob.setMsg("success");
        return ob;
    }
    /**
     *    审核失败
     */
    @RequestMapping(value = "/lose", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject lose(String designId,String loseContent)  {
        logger.info("/backstageRotationChart/specific 审核失败, designId={},loseContent={}", designId,loseContent);
        ResponseObject ob = new ResponseObject();
        Integer specific;
        try {
            specific = backstageRotationChartService.lose(designId,loseContent);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        uuidUtil.importSongData();
        ob.setCode(0);
        ob.setData(specific);
        ob.setMsg("success");
        return ob;
    }

    /**
     * @param
     * @return    隐藏
     */
    @RequestMapping(value = "/hide", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject hide(String id,String commentId,String content) {
        logger.info("/backstageRotationChart/hide 隐藏 id={},commentId={},content={}",id,commentId,content);
        ResponseObject ob = new ResponseObject();
        Integer listall;
        listall = backstageRotationChartService.hide(id,commentId,content);
        ob.setData(listall);
        ob.setCode(0);
        ob.setMsg("请求成功");
        return ob;
    }

    /**
     * @param
     * @return    删除评论
     */
    @RequestMapping(value = "/deleteComment", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject deleteComment(String id,String commentId,String userId) throws Exception {
        logger.info("/backstageRotationChart/stopUser 删除评论 id={},commentId={},userId={}",id,commentId,userId);
        ResponseObject ob = new ResponseObject();
        Integer listall;
        listall  = iCommentService.deleteComment(id,commentId,userId,"3");
        ob.setData(listall);
        ob.setCode(0);
        ob.setMsg("请求成功");
        return ob;

    }
}
